# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=podman
pkgver=4.8.3
pkgrel=0
pkgdesc="Simple management tool for pods, containers and images"
url="https://podman.io/"
license="Apache-2.0"
# s390x: blocked by aardvark-dns and netavark
arch="all !s390x"
options="!check" # tests require root privileges
depends="
	conmon
	oci-runtime
	iptables
	slirp4netns
	shadow-subids
	containers-common
	netavark
	aardvark-dns
	catatonit
	"
makedepends="
	bash
	btrfs-progs-dev
	go
	go-md2man
	gpgme-dev
	grep
	libassuan-dev
	libseccomp-dev
	mandoc
	sqlite-dev
	"
install="$pkgname.post-install"
subpackages="
	$pkgname-doc
	$pkgname-openrc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	$pkgname-remote:remote
	$pkgname-docker:docker:noarch
	$pkgname-docker-doc:docker_doc:noarch
	"
source="https://github.com/containers/podman/archive/v$pkgver/podman-$pkgver.tar.gz
	no-quadlet.patch

	podman.initd
	podman.confd
	"

# secfixes:
#   4.8.2-r1:
#     - CVE-2023-48795
#   4.4.3-r0:
#     - CVE-2022-41723
#   4.4.2-r0:
#     - CVE-2023-0778
#   4.3.0-r0:
#     - CVE-2022-2989
#   4.0.3-r0:
#     - CVE-2022-27649
#   3.4.4-r0:
#     - CVE-2021-4024
#     - CVE-2021-41190
#   3.2.3-r0:
#     - CVE-2021-3602
#   3.0.0-r0:
#     - CVE-2021-20199
#   2.0.5-r0:
#     - CVE-2020-14370
#   1.8.1-r0:
#     - CVE-2020-1726

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	# https://github.com/mattn/go-sqlite3/issues/1164
	export CGO_CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE"

	export BUILDTAGS="exclude_graphdriver_devicemapper seccomp apparmor libsqlite3"
	make -j1 podman podman-remote rootlessport docs \
		PREFIX=/usr \
		GOMD2MAN="$(which go-md2man)"
}

package() {
	make install.bin install.remote install.man install.completions \
		PREFIX=/usr DESTDIR="$pkgdir"

	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname

	# remove systemd files
	rm -r "$pkgdir"/usr/lib/tmpfiles.d
}

remote() {
	pkgdesc="Remote CLI for Podman"
	amove usr/bin/podman-remote
}

docker() {
	pkgdesc="Emulate Docker CLI using Podman"
	depends="podman"
	provides="docker"

	cd "$builddir"

	install -d "$subpkgdir"/usr/bin
	make PREFIX=/usr DESTDIR="$subpkgdir" install.docker

	# Remove man pages
	rm -rf "$subpkgdir"/usr/share

	# Remove systemd files
	rm -rf "$subpkgdir"/usr/lib
}

docker_doc() {
	pkgdesc="Emulate Docker CLI using Podman (documentation)"
	depends="$pkgname-doc"
	install_if="docs $pkgname-docker=$pkgver-r$pkgrel"

	# make target install.docker nor docker-docs are of any use,
	# so lets create the symlinks manually:
	cd "$builddir"/docs/build/man

	mkdir -p "$subpkgdir"/usr/share/man/man1
	for i in podman*.1; do
		ln -s $i.gz "$subpkgdir"/usr/share/man/man1/${i/podman/docker}.gz
	done
}

sha512sums="
13ade866b888d32ada3b38130d7cc4677591136e25234e040b478c5d002d1b7907ed46731996d25cc41b992b98b75f109c6e6eea44251f4ad89162b20266976d  podman-4.8.3.tar.gz
bc0c8d110f72c50d04b214bb2339e1a0ee55cd4c7be10de2819a406fb92422b9f1513a96c12815c6007093196472d110cfc02f7d12cebf9ff8978bfc3159889a  no-quadlet.patch
f8941dc3f8c6b08b288e3347ef2d782140f6e46809da0353f3695338a2de75a971b312e57d09b0a0ea51557568d888b367e3b234be550aea8386321878f4a22f  podman.initd
ec6e6d3f72d0ab6c90a30b2cca5152c0d0f1e402ae671289263d7bf3b5141de9d67c3593f20b6075cedd214b7fb1506e69ff7b4f9691b43b391389343ab9b9b1  podman.confd
"
